#!/bin/bash

# This script customize the HMC console
cd /etc/pam.d
for i in *
do
  if [ "$i" != "passwd" -a "$i" != "su" ]
  then
     x=`grep "pam_hsc.so" $i 2>/dev/null`
     if [ $? -eq 1 ]
     then
        echo "auth    required    /lib/security/pam_hsc.so" >> $i
     fi
  fi
done
cd /
if [ -f /etc/X11/xdm/Xresources ]
then
   /bin/sed -e 's/\!xlogin\*logoFileName/xlogin\*logFileName/g' /etc/X11/xdm/Xresources >/tmp/newXresources
   x=`grep XFree86.xpm /etc/X11/xdm/Xresources 2>/dev/null`
   if [ $? -eq 0 ]
   then
     /bin/sed -e 's/XFree86.xpm/hsc_login.xpm/g' /tmp/newXresources > /etc/X11/xdm/Xresources
   else
     cp /tmp/newXresources /etc/X11/xdm/Xresources
   fi
   /bin/sed -e 's/Hardware Management Console for pSeries/Hardware Management Console/g' /etc/X11/xdm/Xresources > /tmp/newXresources
   cp /tmp/newXresources /etc/X11/xdm/Xresources
   rm -f /tmp/newXresources
fi
#if [ -f /etc/xinetd.d/rexec ]
#then
#   /sbin/chkconfig rexec off
#fi
#if [ -f /etc/xinetd.d/wu-ftpd ]
#then
#   /sbin/chkconfig wu-ftpd off
#fi

if [ -f /etc/crontab ]
then
  x=`grep "MAILTO=root" /etc/crontab`
  if [ $? -eq 0 ]
  then
    sed -e 's/MAILTO=root/MAILTO=/g' /etc/crontab > /tmp/_newCrontab
    cp /tmp/_newCrontab /etc/crontab
  fi
fi

if [ -f /etc/rc.d/rc.local ]
then
  x=`grep "touch /var/lock/subsys/local" /etc/rc.d/rc.local`
  if [ $? -eq 1 ]
  then
    echo "touch /var/lock/subsys/local" >>/etc/rc.d/rc.local
  fi
#  
# The restores are now done during init.d processing at S07 level. 3/21/02 - SLF
#  
#  x=`grep "/opt/hsc/bin/restore 2>/dev/null" /etc/rc.d/rc.local`
#  if [ $? -eq 1 ]
#  then
#    echo "/opt/hsc/bin/restore 2>/dev/null" >>/etc/rc.d/rc.local
#  fi
#  x=`grep "/opt/hsc/bin/restoreUpgradeFiles 2>/dev/null" /etc/rc.d/rc.local`
#  if [ $? -eq 1 ]
#  then
#    echo "/opt/hsc/bin/restoreUpgradeFiles 2>/dev/null" >>/etc/rc.d/rc.local
#  fi

  x=`grep "/opt/hsc/bin/cfgRMC" /etc/rc.d/rc.local`
  if [ $? -eq 1 ]
  then
    echo "/opt/hsc/bin/cfgRMC 2>>/dev/null" >>/etc/rc.d/rc.local
  fi

  x=`grep "/etc/rc.d/init.d/epca start 2>/dev/null" /etc/rc.d/rc.local`
  if [ $? -eq 1 ]
  then
    if [ -f /etc/rc.d/init.d/epca ]
    then
       echo "/etc/rc.d/init.d/epca start 2>/dev/null" >>/etc/rc.d/rc.local
    fi
  fi
  x=`grep "/usr/sbin/cfg8port" /etc/rc.d/rc.local`
  if [ $? -eq 1 ]
  then
    if [ -f /usr/sbin/cfg8port ]
    then 
       echo "/usr/sbin/cfg8port 1 2>/dev/null" >>/etc/rc.d/rc.local
    fi
  fi

  x=`grep "/sbin/hdparm" /etc/rc.d/rc.local`
  if [ $? -eq 1 ]
  then
    echo "/sbin/hdparm -u1 -m16 -c3 /dev/hda" >>/etc/rc.d/rc.local
  fi

# We decided to not write the trace log to the file.
  x=`grep "/usr/sbin/iqzdtcon" /etc/rc.d/rc.local`
  if [ $? -eq 0 ]
  then
    sed -e 's/\/usr\/sbin\/iqzdtcon/#\/usr\/sbin\/iqzdtcon/' /etc/rc.d/rc.local
> /opt/hsc/data/rc_local.dup
    cp -f /opt/hsc/data/rc_local.dup /etc/rc.d/rc.local
    rm -f /opt/hsc/data/rc_local.dup
  fi
  x=`grep "cp -pf /opt/hsc/data/iqzdtrac.trm /opt/hsc/data/iqzdtrac.trm.previous" /etc/rc.d/rc.local`
  if [ $? -eq 1 ]
  then
    echo "if [ -f /opt/hsc/data/iqzdtrac.trm ]" >> /etc/rc.d/rc.local
    echo "then" >>/etc/rc.d/rc.local
    echo "   cp -pf /opt/hsc/data/iqzdtrac.trm /opt/hsc/data/iqzdtrac.trm.previous" >>/etc/rc.d/rc.local
    echo "fi" >>/etc/rc.d/rc.local
  fi

fi
# Check to see if toolbar has the Xlock

x=`grep "xlock" /usr/X11R6/lib/X11/icewm/toolbar`
if [ $? -eq 1 ]
then
  echo "prog Lock-Console xlock xlock" >> /usr/X11R6/lib/X11/icewm/toolbar
  if [ -f /usr/X11R6/lib/X11/app-defaults/XLock ]
  then
	sed -e /XLock.program:/d /usr/X11R6/lib/X11/app-defaults/XLock > /tmp/.saved_XLock_
	sed -e /XLock.messagesfile:/d /tmp/.saved_XLock_ > /usr/X11R6/lib/X11/app-defaults/XLock
	sed -e /XLock.message:/d /usr/X11R6/lib/X11/app-defaults/XLock > /tmp/.saved_XLock_
	sed -e /XLock.messagefile:/d /tmp/.saved_XLock_ > /usr/X11R6/lib/X11/app-defaults/XLock
	rm -rf /tmp/.saved_XLock_
  fi        
fi
exit 0
